//
//  HomeParLeaveDetailController.m
//  ChatDemo-UI2.0
//
//  Created by syun on 16/8/15.
//  Copyright © 2016年 syun. All rights reserved.
//

#import "HomeParLeaveDetailController.h"
#import "HomeLeaveCell.h"
#import "HomeLeavedetail_top_Cell.h"
#import "HomeLeaveDetail_center_Cell.h"
#import "HomeTearchReplayCell.h"
#import "TearchReplyModel.h"
#import "SY_Home_LeavingReplyViewController.h"
#import "SY_Activity_Model.h"
#import "SYMessageTool.h"
@interface HomeParLeaveDetailController ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate,reloadDataDelegate>
{
    UIButton *cancelBtn;
    UIButton *secondBtn;
    UIButton *replyBtn;
    UIView *line;
    
    HomeparLeaveDetailModel *detailModel;
    
    NSString *startTime;
    NSString *endTime;
    
    NSInteger leavdID;
    
    EmptyStateView *noWifiView;//无网络状态
    
}
@property(nonatomic,strong)UITableView *table;
@property(nonatomic,strong)NSMutableArray *replylistArray;
@end

@implementation HomeParLeaveDetailController

- (NSMutableArray *)replylistArray
{
    if (_replylistArray==nil) {
        
        _replylistArray=[NSMutableArray array];
    }
    return _replylistArray;
}

- (UITableView *)table {
    if (_table==nil) {
        _table=[[UITableView alloc]initWithFrame:CGRectMake(0, SafeAreaTopHeight, SCREENWIDTH, SCREENHEIGH - SafeAreaTopHeight -SafeAreaBottomHeight-49) style:UITableViewStylePlain];
        _table.delegate=self;
        _table.dataSource=self;
        _table.hidden = YES;
        _table.backgroundColor=RGBACOLOR(240, 239, 245, 1);
        _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    }
    return _table;
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:YES];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    self.view.backgroundColor=RGBACOLOR(240, 239, 245, 1);
    self.view.backgroundColor = [UIColor colorWithHexString:@"#f4f5f7"];
    self.navBar.nav_titleLabel.text=@"请假条";
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.view.backgroundColor=RGBACOLOR(240, 239, 245, 1);
   
    noWifiView = [[EmptyStateView alloc] initNoWifiWithFrame:CGRectMake(0, (SCREENHEIGH-64-175)/2, SCREENWIDTH, 175) andBackImage:@"noWifi" andBottomStr:@"网络出错啦,点击重新加载"];
    noWifiView.userInteractionEnabled= YES;
    noWifiView.delegate = self;
    [self.view addSubview:noWifiView];
    
    if (_leaveid>0) {
        
        leavdID=_leaveid;
        
    }else
    {
        leavdID=_lmodel.leaveid;
    }
    
    [self requestLeaveDetailData];
    [self.view addSubview:self.table];
   
   [self changeReadState];
   
}
- (void)changeReadState{
   
   SY_Activity_Model * model = [[SY_Activity_Model alloc]init];
   model.readState = 1;
   
   if (_leaveid>0) {
      
      model.infoid = [NSString stringWithFormat:@"%ld",_leaveid];
      
   }else{
      
      model.infoid = [NSString stringWithFormat:@"%ld", _lmodel.leaveid];
   }
   
   [SYMessageTool updataMessageModel:model];
   
}
- (void)back
{
    if ([self.noreadFlag isEqualToString:@"noread"]) {
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshNoReadNum" object:nil];
    }
    
    [self.navigationController popViewControllerAnimated:YES];
    
}
- (void)dealloc {
    
    NSLog(@"销毁");
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

-(void)loadButtons {

    
    NSDate *nowDate = [NSDate date];
    NSString *dayString = [[nowDate description] substringToIndex:10];
    
    NSUInteger nowtime = [Utils transformStringToNsinterger:dayString];
    
    NSUInteger endtime = [Utils transformStringToNsinterger:[detailModel.endtime substringToIndex:10]];
    
    NSUInteger startTim = [Utils transformStringToNsinterger:[detailModel.starttime substringToIndex:10]];
    
    NSLog(@"nowtime%luendtime%lustartTim%lu",(unsigned long)nowtime,(unsigned long)endtime,(unsigned long)startTim);
    
    NSString *isread=[NSString stringWithFormat:@"%ld",(long)detailModel.isread];
    
    [cancelBtn removeFromSuperview];
    [replyBtn removeFromSuperview];
    [secondBtn removeFromSuperview];
    
    
    line.hidden = YES;

    
    if ([SYAccountTool ShareAccount].account.lasttype == 2) {

        
        line=[[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGH-49.5+64, SCREENWIDTH, 0.5)];
        line.backgroundColor=RGBACOLOR(199, 199, 204, 1);
       line.backgroundColor = [UIColor redColor];
        [self.view addSubview:line];
        
        if (nowtime<startTim) {
            
            if (detailModel.recalltime.length>0) {
                line.hidden=YES;
            }else {
                
            if ([isread isEqualToString:@"0"]) {
                    cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
                    cancelBtn.frame=CGRectMake(0, SCREENHEIGH-49-SafeAreaBottomHeight, SCREENWIDTH/2, 49);
                    [cancelBtn setTitle:@"撤销" forState:UIControlStateNormal];
                    [cancelBtn addTarget:self action:@selector(cancelLeaveAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cancelBtn setBackgroundColor:[UIColor whiteColor]];
                    [cancelBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
                    [self.view addSubview:cancelBtn];
                    
                    secondBtn=[UIButton buttonWithType:UIButtonTypeCustom];
                    secondBtn.frame=CGRectMake( SCREENWIDTH/2, SCREENHEIGH-49-SafeAreaBottomHeight, SCREENWIDTH/2, 49);
                    [secondBtn setTitle:@"再次通知" forState:UIControlStateNormal];
                    [secondBtn addTarget:self action:@selector(secondLeaveAction:) forControlEvents:UIControlEventTouchUpInside];
                    [secondBtn setBackgroundColor:[UIColor whiteColor]];
                    [secondBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
                    [self.view addSubview:secondBtn];
                    
                    UIView *hLine=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 1, 49)];
                    hLine.backgroundColor=RGBACOLOR(199, 199, 204, 1);
                    [secondBtn addSubview:hLine];
                }else
                {
                    cancelBtn=[UIButton buttonWithType:UIButtonTypeCustom];
                    cancelBtn.frame=CGRectMake(0, SCREENHEIGH-49-SafeAreaBottomHeight, SCREENWIDTH, 49);
                    [cancelBtn setTitle:@"撤销" forState:UIControlStateNormal];
                    [cancelBtn addTarget:self action:@selector(cancelLeaveAction:) forControlEvents:UIControlEventTouchUpInside];
                    [cancelBtn setBackgroundColor:[UIColor whiteColor]];
                    [cancelBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
                    [self.view addSubview:cancelBtn];
                }
            }
            
        } else if (startTim<=nowtime<=endtime) {
            
            if (detailModel.recalltime.length>0) {
                
                line.hidden=YES;
                
            }else {
                
                if ([isread isEqualToString:@"0"]) {
                    secondBtn=[UIButton buttonWithType:UIButtonTypeCustom];
                    secondBtn.frame=CGRectMake( 0, SCREENHEIGH-49 - SafeAreaBottomHeight, SCREENWIDTH, 49);
                    [secondBtn setTitle:@"再次通知" forState:UIControlStateNormal];
                    [secondBtn addTarget:self action:@selector(secondLeaveAction:) forControlEvents:UIControlEventTouchUpInside];
                    [secondBtn setBackgroundColor:[UIColor whiteColor]];
                    [secondBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
                    [self.view addSubview:secondBtn];
                    
                }else
                {
                    line.hidden=YES;
                }
            }
        }else
        {
            line.hidden=YES;
        }
        
    }else {
        
        if (nowtime <= endtime) {
            if (detailModel.recalltime.length == 0) {
                if (detailModel.replynum <= 0) {
                    
                    line=[[UIView alloc]initWithFrame:CGRectMake(0, SCREENHEIGH-49.5-SafeAreaBottomHeight, SCREENWIDTH, 0.5)];
                    line.backgroundColor=RGBACOLOR(199, 199, 204, 1);
                    [self.view addSubview:line];
                    
                    replyBtn=[UIButton buttonWithType:UIButtonTypeCustom];
                    replyBtn.frame=CGRectMake(0, SCREENHEIGH-49-SafeAreaBottomHeight, SCREENWIDTH, 49);
                    [replyBtn setTitle:@"回复" forState:UIControlStateNormal];
                    [replyBtn addTarget:self action:@selector(replyAction:) forControlEvents:UIControlEventTouchUpInside];
                    [replyBtn setBackgroundColor:[UIColor whiteColor]];
                    [replyBtn setTitleColor:RGBACOLOR(57, 173, 255, 1) forState:UIControlStateNormal];
                    [self.view addSubview:replyBtn];
                    
                }
                
            }
            
        }
        
    }
    

}
- (void)cancelLeaveAction:(UIButton *)sender
{
    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:@"您确定要撤销此请假吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    alert.tag=100;
    [alert show];

    
   
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    if (alertView.tag==100) {
        
        
        if (buttonIndex==0) {
            
            return;
        }

        BaseModel *param = [BaseModel param];
        param.method = @"api_leave_delete";
        param.leaveid = [NSString stringWithFormat:@"%ld",leavdID];
        
        [Utils get:nil parameters:param.mj_keyValues success:^(NSInteger recode, id jsonObject) {
            
            NSString *message=[jsonObject objectForKey:@"re_info"];
            
            UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            alert.tag=101;
            [alert show];
            
        } failure:^(NSInteger recode, NSError *error) {
            
        }];

    }
    
    if (alertView.tag==101) {
        
        cancelBtn.hidden=YES;
        secondBtn.hidden=YES;
        line.hidden=YES;
        [self requestLeaveDetailData];
    }
    
//    if (alertView.tag == 103) {
//        [self.navigationController popViewControllerAnimated:YES];
//    }
}
- (void)secondLeaveAction:(UIButton *)sender
{
    BaseModel *param = [BaseModel param];
    param.method = @"api_leave_remindagain";
    param.leaveid=[NSString stringWithFormat:@"%ld",leavdID];
    
    [Utils get:nil parameters:param.mj_keyValues success:^(NSInteger recode, id jsonObject) {
        
        NSString *message=[jsonObject objectForKey:@"re_info"];
        
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:nil message:message delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        alert.tag=102;
        [alert show];
        
    } failure:^(NSInteger recode, NSError *error) {
        
    }];

}

- (void)replyAction:(UIButton *)sender {
    
    SY_Home_LeavingReplyViewController *replyVC = [[SY_Home_LeavingReplyViewController alloc]init];
    
    if (self.lmodel) {
        
        replyVC.toUserID = [NSString stringWithFormat:@"%ld",(long)self.lmodel.parentid];
    }else if (self.toUseridStr) {
        replyVC.toUserID = _toUseridStr;
    }else {
        
        [self showHint:@"touserid 不能为0"];
        return;
    }
    
    replyVC.parentID = replyVC.toUserID;
    replyVC.leaveID = [NSString stringWithFormat:@"%ld",(long)detailModel.leaveid];
    replyVC.leavingReply = ^(){
        [self requestLeaveDetailData];
    };

    [self.navigationController pushViewController:replyVC animated:YES];
    
}
- (void)requestLeaveDetailData
{
    BaseModel *param = [BaseModel param];
    param.method = @"api_leave_info";
    param.teacherid = USERID;
    param.leaveid=[NSString stringWithFormat:@"%ld",leavdID];
    
    [Utils get:nil parameters:param.mj_keyValues success:^(NSInteger recode, id jsonObject) {
        
        NSArray *array=[jsonObject objectForKey:@"re_data"];
        NSDictionary *dict=[array lastObject];
        if (dict.count>0) {
            self->detailModel=[HomeparLeaveDetailModel mj_objectWithKeyValues:dict];
            NSArray *replyArray=[dict objectForKey:@"replylist"];
            _toUseridStr = [NSString stringWithFormat:@"%@",[dict objectForKey:@"parentid"]];
            if (replyArray.count>0) {
                [self.replylistArray removeAllObjects];
                for (NSDictionary *dic in replyArray) {
                    TearchReplyModel *replyModel=[TearchReplyModel mj_objectWithKeyValues:dic];
                    [self.replylistArray addObject:replyModel];
                }
            }
            
            [self loadButtons];
            
            [self.table reloadData];
            self.table.hidden = NO;
        }else {
            self.table.hidden = YES;
            UILabel *emptyLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 200, SCREENWIDTH, 17)];
            [emptyLab setTextAlignment:NSTextAlignmentCenter];
            [emptyLab setFont:[UIFont systemFontOfSize:17]];
            [emptyLab setTextColor:colorFromHex(@"979797")];
            [emptyLab setText:@"暂无数据"];
            [self.view addSubview:emptyLab];
        }
        
        
    } failure:^(NSInteger recode, NSError *error) {
        
        if (error.code == -1009) {
            
            self.table.hidden = YES;
            [self ->noWifiView showEmptyImage];
        }
        
    }];
    
}

- (void)reloadCurrentData
{
    self.table.hidden = NO ;
    [noWifiView hideEmptyImage];
    [self requestLeaveDetailData];
}


#pragma mark -UITableViewDataSource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    if (detailModel.recalltime.length>0) {
        return 5;
    }else
    {
        return 4;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row==0) {
        
        return 62;
        
    }else if (indexPath.row==1)
    {
        
        return detailModel.cellHeight;
        
    }else if (indexPath.row==2)
    {
        return 52;
        
    }else if (indexPath.row == 3){
        NSString *isreply=[NSString stringWithFormat:@"%ld",(long)detailModel.replynum];
        
        if ([isreply isEqualToString:@"1"]) {
            if (self.replylistArray.count>0) {
                TearchReplyModel *model=[self.replylistArray lastObject];
                return model.cellHeight;
            }
        }else
        {
            return 52;
        }
    }
    return 52;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *jointime=[Utils getDataStringWithoutSecondString:detailModel.jointime];
    
    if (indexPath.row==0) {
        HomeLeaveCell*cell=[self.table dequeueReusableCellWithIdentifier:@"HomeLeaveCell"];
        
        if(cell==nil)
        {
            NSArray *arr=[[NSBundle mainBundle]loadNibNamed:@"HomeLeaveCell" owner:nil options:nil];
            cell=[arr objectAtIndex:0];
        }
        
        cell.leaveTime.hidden=YES;
        cell.detailMark.hidden=YES;
        cell.leaveTitle.text=[NSString stringWithFormat:@"%@的请假申请",detailModel.studentname];
        cell.leaveClass.text=detailModel.classname;
        
        if (detailModel.studentlogo.length>0) {
            if (![detailModel.studentlogo hasPrefix:@"http"] && detailModel.studentlogo) {
                NSString * logo = [REQUESTIMAGEURL stringByAppendingString:detailModel.studentlogo];
                [cell.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
            }
        }else
        {
            cell.headImage.image=[UIImage imageNamed:@"logo_01"];
        }
        
        
        int logotype=(int)detailModel.studentlogotype;
        NSString *nameStr=detailModel.studentname;
        if (logotype==0) {
            cell.headName.hidden=YES;
            if (detailModel.studentname.length>2) {
                nameStr = [nameStr substringFromIndex:nameStr.length-2];
                cell.headName.text=nameStr;
            }else
            {
                cell.headName.text=nameStr;
            }
        }else
        {
            cell.headName.hidden=YES;
        }
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;

        return cell;
        
    }else if (indexPath.row==1)
    {
        HomeLeaveDetail_center_Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLeaveDetail_center_Cell"];
        
        if (cell == nil) {
            
            cell = [[HomeLeaveDetail_center_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeLeaveDetail_center_Cell"];
        }
        
        cell.applyParentCont.text=detailModel.parentname;
        cell.leaveTypeCont.text=detailModel.typename;
        
        if (detailModel.starttime.length>10) {
            startTime=[detailModel.starttime substringToIndex:10];
        }
        if (detailModel.endtime.length>10) {
            endTime=[detailModel.endtime substringToIndex:10];
        }
        
        cell.leaveTimeCont.text=[NSString stringWithFormat:@"%@至%@",startTime,endTime];
        cell.leaveDaysCont.text=[NSString stringWithFormat:@"%@ 天",detailModel.flong];
        
        cell.leaveReasonCont.frame=CGRectMake(12+75+10, cell.leaveReason.frame.origin.y, SCREENWIDTH-24-10-75,[self resizeContenLabelHeightWithSting:detailModel.scontent]);
        cell.leaveReasonCont.text=detailModel.scontent;
        cell.leaveReasonCont.numberOfLines = 0;
        cell.leaveReasonCont.clipsToBounds = YES;

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else if (indexPath.row==2)
    {
        HomeLeavedetail_top_Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLeavedetail_top_Cell"];
        
        if (cell == nil) {
            
            cell = [[HomeLeavedetail_top_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeLeavedetail_top_Cell"];
        }
        
        //头像类型
        int logoType = (int)detailModel.parentlogotype;
        
        //昵称
        NSString *parentname = detailModel.parentname;
        
        if (parentname.length > 2) {
            parentname = [parentname substringFromIndex:parentname.length-2];
        }
        
        cell.headView.flag = logoType == 1?YES:NO;
        cell.headView.namelabel.font = [UIFont systemFontOfSize:14];
        cell.headView.namelabel.text = parentname;
        cell.headView.layer.cornerRadius = 19;
        
        NSString *logo = detailModel.parentlogo;
        if (logo && ![logo hasPrefix:@"http"]) {
            
            logo = [REQUESTIMAGEURL stringByAppendingString:logo];
            
        }
        
        [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        
        cell.nameLabel.text  = detailModel.parentname;
        
        
        cell.timeLabel.text  = jointime;
        
        cell.stateLabel.text = @"发起请假";
        
        UIView *cellLine=[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 0.5)];
        cellLine.backgroundColor=RGBACOLOR(199, 199, 204, 1);
        [cell.contentView addSubview:cellLine];
        
        UIView *cellLine2=[[UIView alloc]initWithFrame:CGRectMake(60,51.5, SCREENWIDTH, 0.5)];
        cellLine2.backgroundColor=RGBACOLOR(199, 199, 204, 1);
        [cell.contentView addSubview:cellLine2];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
        
    }else if (indexPath.row==3)
    {
        NSString *isread=[NSString stringWithFormat:@"%ld",(long)detailModel.isread];
        NSString *isreply=[NSString stringWithFormat:@"%ld",(long)detailModel.replynum];
        //1有回复
        if ([isreply isEqualToString:@"1"]) {
            
            HomeTearchReplayCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeTearchReplayCell"];
            
            if (cell == nil) {
                
                cell = [[HomeTearchReplayCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeTearchReplayCell"];
            }
            TearchReplyModel *tearchModel=[self.replylistArray lastObject];
            
             NSString *replyTime=[Utils getDataStringWithoutSecondString:tearchModel.jointime];
            //头像类型
            int logoType = (int)detailModel.teacherlogotype;
            
            //昵称
            NSString *teachername =[NSString stringWithFormat:@"%@老师",detailModel.teachername];
            
            cell.nameLabel.text=teachername;
            
            if (teachername.length > 2) {
                teachername = [teachername substringFromIndex:teachername.length-2];
            }
            
            cell.headView.flag = logoType == 1?YES:NO;
            cell.headView.namelabel.font = [UIFont systemFontOfSize:14];
            cell.headView.namelabel.text = teachername;
            cell.headView.layer.cornerRadius = 19;
            
            NSString *logo = detailModel.teacherlogo;
            if (logo && ![logo hasPrefix:@"http"]) {
                
                logo = [REQUESTIMAGEURL stringByAppendingString:logo];
                
            }
            
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
            
            cell.timeLabel.text=replyTime;
            
            cell.contentLabel.frame=CGRectMake(cell.nameLabel.frame.origin.x, cell.nameLabel.frame.origin.y+cell.nameLabel.frame.size.height+10, SCREENWIDTH-24-10-38,tearchModel.cellHeight-42);
            cell.contentLabel.text=tearchModel.scontent;
            
            
            UIView *cellLine=[[UIView alloc]initWithFrame:CGRectMake(60,tearchModel.cellHeight-0.5, SCREENWIDTH, 0.5)];
            
            cellLine.backgroundColor=RGBACOLOR(199, 199, 204, 1);
            if (detailModel.recalltime.length == 0) {
                cellLine.x = 0;
            }else
            {
                 cellLine.x = 60;
            }
            
            [cell.contentView addSubview:cellLine];
            
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
            
        }else
        {
            HomeLeavedetail_top_Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLeavedetail_top_Cell"];
            
                
            cell = [[HomeLeavedetail_top_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeLeavedetail_top_Cell"];
            
            
            //头像类型
            int logoType = (int)detailModel.teacherlogotype;
            
            //昵称
            NSString *teachername;
            
            
            if (detailModel.teachername.length > 2) {
                teachername = [detailModel.teachername substringFromIndex:detailModel.teachername.length-2];
            }
            
            cell.headView.flag = logoType == 1?YES:NO;
            cell.headView.namelabel.font = [UIFont systemFontOfSize:14];
            cell.headView.namelabel.text = teachername;
            cell.headView.layer.cornerRadius = 19;
            
            NSString *logo = detailModel.teacherlogo;
            if (logo && ![logo hasPrefix:@"http"]) {
                
                logo = [REQUESTIMAGEURL stringByAppendingString:logo];
            }
            
            [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
            
            cell.nameLabel.text = [NSString stringWithFormat:@"%@老师",detailModel.teachername];
            
            
            
            if ([isread isEqualToString:@"0"]) {
                
                cell.stateLabel.text=@"未读";
                cell.stateLabel.textColor = RGBACOLOR(59, 59, 59, 1);
                cell.timeLabel.text =jointime ;
                
            }else {
                
                cell.stateLabel.text=@"已读";
                
                if (detailModel.readtime.length>0) {
                    NSString *readtime=[Utils getDataStringWithoutSecondString:detailModel.readtime];

                    cell.timeLabel.text =readtime;
                }
                
                
            }
            
            UIView *cLine=[[UIView alloc]init ];
            cLine.backgroundColor=RGBACOLOR(199, 199, 204, 1);
            
            if (detailModel.recalltime.length > 0) {
                
                cLine.frame=CGRectMake(60,51.5, SCREENWIDTH, 0.5);
            }else
            {
                cLine.frame=CGRectMake(0,51.5, SCREENWIDTH, 0.5);
            }
            [cell.contentView addSubview:cLine];
            
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            return cell;
        }
        
    }else
    {
        HomeLeavedetail_top_Cell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomeLeavedetail_top_Cell"];
        
        cell = [[HomeLeavedetail_top_Cell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"HomeLeavedetail_top_Cell"];
        
        
        //头像类型
        int logoType = (int)detailModel.parentlogotype;
        
        //昵称
        NSString *parentname = detailModel.parentname;
        
        
        if (parentname.length > 2) {
            parentname = [parentname substringFromIndex:parentname.length-2];
        }
        
        cell.headView.flag = logoType == 1?YES:NO;
        cell.headView.namelabel.font = [UIFont systemFontOfSize:14];
        cell.headView.namelabel.text = parentname;
        cell.headView.layer.cornerRadius = 19;
        
        NSString *logo = detailModel.parentlogo;
        if (logo && ![logo hasPrefix:@"http"]) {
            
            logo = [REQUESTIMAGEURL stringByAppendingString:logo];
            
        }
        
        [cell.headView.headImage sd_setImageWithURL:[NSURL URLWithString:logo]];
        
        cell.nameLabel.text=detailModel.parentname;
        
        if (detailModel.recalltime!=nil&&detailModel.recalltime.length>0) {
            
            NSString *recalltime=[Utils getProperDataStringWithString:detailModel.recalltime];
            if (recalltime.length>3) {
                
                recalltime=[recalltime substringToIndex:recalltime.length-3];
                cell.timeLabel.text=recalltime;
            }
        }
        cell.stateLabel.text=@"撤销";
        
        UIView *cellLine=[[UIView alloc]initWithFrame:CGRectMake(0 , 51.5, SCREENWIDTH, 0.5)];
        cellLine.backgroundColor=RGBACOLOR(199, 199, 204, 1);
        [cell.contentView addSubview:cellLine];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}
- (CGFloat)resizeContenLabelHeightWithSting:(NSString *)text
{
    if (text.length == 0) {
        return 0;
    }
    UIFont *font = [UIFont systemFontOfSize:15];
    
    NSStringDrawingOptions opts = NSStringDrawingUsesLineFragmentOrigin;
    
    //NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    //[style setLineBreakMode:NSLineBreakByCharWrapping];
    
    NSDictionary *attributes = @{ NSFontAttributeName : font};
    
    CGSize maxSize = CGSizeMake(SCREENWIDTH-24-10-75, 6000);
    CGSize size = [text boundingRectWithSize:maxSize
                                     options:opts
                                  attributes:attributes
                                     context:nil].size;
    return size.height ;
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
